home *** CD-ROM | disk | FTP | other *** search
- Public Class SubclassingForm
- Inherits System.Windows.Forms.Form
-
- #Region " Windows Form Designer generated code "
-
- Public Sub New()
- MyBase.New()
-
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
-
- 'Add any initialization after the InitializeComponent() call
-
- End Sub
-
- 'Form overrides dispose to clean up the component list.
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
- Friend WithEvents lblStatus As System.Windows.Forms.Label
-
- 'Required by the Windows Form Designer
- Private components As System.ComponentModel.Container
-
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- Me.CheckBox1 = New System.Windows.Forms.CheckBox()
- Me.lblStatus = New System.Windows.Forms.Label()
- Me.SuspendLayout()
- '
- 'CheckBox1
- '
- Me.CheckBox1.Location = New System.Drawing.Point(24, 24)
- Me.CheckBox1.Name = "CheckBox1"
- Me.CheckBox1.Size = New System.Drawing.Size(168, 24)
- Me.CheckBox1.TabIndex = 1
- Me.CheckBox1.Text = "Enable subclassing"
- '
- 'lblStatus
- '
- Me.lblStatus.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
- Me.lblStatus.Dock = System.Windows.Forms.DockStyle.Bottom
- Me.lblStatus.Location = New System.Drawing.Point(0, 141)
- Me.lblStatus.Name = "lblStatus"
- Me.lblStatus.Size = New System.Drawing.Size(456, 32)
- Me.lblStatus.TabIndex = 0
- '
- 'SubclassingForm
- '
- Me.AutoScaleBaseSize = New System.Drawing.Size(7, 17)
- Me.ClientSize = New System.Drawing.Size(456, 173)
- Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.CheckBox1, Me.lblStatus})
- Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 11!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.Name = "SubclassingForm"
- Me.Text = "SubclassingForm"
- Me.ResumeLayout(False)
-
- End Sub
-
- #End Region
-
- ' API constants
- Private Const WM_NCHITTEST As Integer = &H84
- Private Const WM_ACTIVATEAPP As Integer = &H1C
- Private Const WM_DISPLAYCHANGE As Integer = &H7E
- Private Const WM_COMPACTING As Integer = &H41
- Private Const WM_GETMINMAXINFO As Integer = &H24
- Private Const HTCAPTION As Integer = 2
- Private Const HTCLIENT As Integer = 1
-
- ' API structures
- Structure POINTAPI
- Dim X As Integer
- Dim Y As Integer
- End Structure
-
- Structure MINMAXINFO
- Dim ptReserved As POINTAPI
- Dim ptMaxSize As POINTAPI
- Dim ptMaxPosition As POINTAPI
- Dim ptMinTrackSize As POINTAPI
- Dim ptMaxTrackSize As POINTAPI
- End Structure
-
- ' this is where we do the subclassing
-
- Protected Overrides Sub WndProc(ByRef m As Message)
- ' let the base form process this message
- MyBase.WndProc(m)
-
- ' exit if subclassing is disabled
- If Not CheckBox1.Checked Then Exit Sub
-
- Select Case m.Msg
- Case WM_DISPLAYCHANGE
- lblStatus.Text = "Screen resolution has changed"
-
- Case WM_COMPACTING
- lblStatus.Text = "The system is low on memory"
-
- Case WM_ACTIVATEAPP
- ' application has been activated or deactivated
- If m.WParam.ToInt32 <> 0 Then
- lblStatus.Text = "Application has been activated"
- Else
- lblStatus.Text = "Application has been deactivated"
- End If
-
- Case WM_NCHITTEST
- ' if on client area, make Windows believe it's on caption
- If m.Result.ToInt32 = HTCLIENT Then
- ' the only way to assing an IntPtr
- m.Result = New IntPtr(HTCAPTION)
- End If
-
- Case WM_GETMINMAXINFO
- Dim mmi As MINMAXINFO
- mmi = CType(m.GetLParam(mmi.GetType), MINMAXINFO)
- lblStatus.Text = String.Format("Max size = ({0}, {1})", mmi.ptMaxSize.X, mmi.ptMaxSize.Y)
- End Select
-
- End Sub
-
-
- End Class
-